package com.ruoyi.project.system.job.controller;

import java.util.List;

import com.ruoyi.project.system.course.domain.Course;
import com.ruoyi.project.system.course.service.ICourseService;
import com.ruoyi.project.system.grades.domain.ClassGrades;
import com.ruoyi.project.system.grades.service.IClassGradesService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.job.domain.JobCourseClass;
import com.ruoyi.project.system.job.service.IJobCourseClassService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 作业-课程-班级记录Controller
 *
 * @author ruoyi
 * @date 2021-04-15
 */
@Controller
@RequestMapping("/system/job")
public class JobCourseClassController extends BaseController
{
    private String prefix = "system/job";

    @Autowired
    private IJobCourseClassService jobCourseClassService;

    @Autowired
    private ICourseService courseService;

    @Autowired
    private IClassGradesService classGradesService;

    @RequiresPermissions("system:job:view")
    @GetMapping()
    public String job()
    {
        return prefix + "/job";
    }

    /**
     * 查询作业-课程-班级记录列表
     */
    @RequiresPermissions("system:job:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JobCourseClass jobCourseClass)
    {
        startPage();
        List<JobCourseClass> list = jobCourseClassService.selectJobCourseClassList(jobCourseClass);
        return getDataTable(list);
    }

    /**
     * 导出作业-课程-班级记录列表
     */
    @RequiresPermissions("system:job:export")
    @Log(title = "作业-课程-班级记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JobCourseClass jobCourseClass)
    {
        List<JobCourseClass> list = jobCourseClassService.selectJobCourseClassList(jobCourseClass);
        ExcelUtil<JobCourseClass> util = new ExcelUtil<JobCourseClass>(JobCourseClass.class);
        return util.exportExcel(list, "class");
    }

    /**
     * 新增作业-课程-班级记录
     */
    @GetMapping("/add/{id}")
    public String add(@PathVariable("id") Long id, ModelMap mmap)
    {
        Course course = courseService.selectCourseById(id);
        mmap.put("courseId",id);
        mmap.put("courseName",course.getName());
        // 获取所有班级信息
        List<ClassGrades> classGradesList = classGradesService.selectClassGradesList(new ClassGrades());
        mmap.put("classGradesList",classGradesList);
        return prefix + "/add";
    }

    /**
     * 新增保存作业-课程-班级记录
     */
    @RequiresPermissions("system:job:add")
    @Log(title = "作业-课程-班级记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JobCourseClass jobCourseClass)
    {
        return toAjax(jobCourseClassService.insertJobCourseClass(jobCourseClass));
    }

    /**
     * 修改作业-课程-班级记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JobCourseClass jobCourseClass = jobCourseClassService.selectJobCourseClassById(id);
        mmap.put("jobCourseClass", jobCourseClass);
        return prefix + "/edit";
    }

    /**
     * 修改保存作业-课程-班级记录
     */
    @RequiresPermissions("system:job:edit")
    @Log(title = "作业-课程-班级记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JobCourseClass jobCourseClass)
    {
        return toAjax(jobCourseClassService.updateJobCourseClass(jobCourseClass));
    }

    /**
     * 删除作业-课程-班级记录
     */
    @RequiresPermissions("system:job:remove")
    @Log(title = "作业-课程-班级记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jobCourseClassService.deleteJobCourseClassByIds(ids));
    }
}
